package src.lab03.Test08;

import java.io.*;

/**
 * Created by lenovo on 2017/12/13.
 */
public class Test {
    public static void main(String[] args) throws IOException {
                    String path1 = "D:\\java\\1.txt";
                    String path2 = "D:\\java\\2.txt";
                    String path3 = "D:\\java\\3.txt";

                           InputStreamReader reader = new InputStreamReader(new FileInputStream(path1));
                    BufferedReader buffer = new BufferedReader(reader);//读1.txt内容

                            InputStreamReader reader1 = new InputStreamReader(new FileInputStream(path2));
                    BufferedReader buffer1 = new BufferedReader(reader1);//读2.txt内容

                            OutputStreamWriter last = new OutputStreamWriter(new FileOutputStream(path3));
                    BufferedWriter writer = new BufferedWriter(last);//写3.txt内容

                            String line1 = buffer.readLine();
                    String line2 = buffer1.readLine();
                    while (true) {

                                   if (line1 != null && line2 != null) {
                                    System.out.println(line1);
                                    System.out.println(line2);
                                    writer.write(line1);
                                    writer.newLine();
                                    writer.write(line2);
                                    writer.newLine();
                                    writer.flush();
                                   line1 = buffer.readLine();
                                    line2 = buffer1.readLine();
                               } else if (line1 == null && line2 != null) {
                                    System.out.println(line2);
                                   writer.write(line2);
                                   writer.newLine();
                                    writer.flush();line2 = buffer1.readLine();
                               } else if (line1 != null && line2 == null) {
                                    System.out.println(line1);
                                    writer.write(line1);
                                    writer.newLine();
                                    writer.flush();
                                    line1 = buffer.readLine();
                               } else {
                                    break;
                                }
                       }
                }
     }

